package com.bjyhl.medical.main.video;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.bjyhl.core.fragments.LatteFragment;
import com.bjyhl.core.fragments.bottom.BaseBottomFragment;
import com.bjyhl.medical.R;
import com.bjyhl.ui.recycler.ItemType;
import com.joanzapata.iconify.widget.IconTextView;

/**
 * Created by Natalya on 2019/1/27 18:22
 * Note: 主页fragment
 */

public class VideoOneTypeFragment extends LatteFragment implements View.OnClickListener {

    TextView videoListTitle = null;
    TextView videoListMore = null;
    IconTextView icon_back = null;
    public static final String ARG_VIDEO_TYPE = "ARG_VIDEO_TYPE";
    public static final String ARG_VIDEO_COUNT = "ARG_VIDEO_COUNT";
    private Integer mVideoCount = 0;
    private String mVideoType = null;
    private BaseBottomFragment baseBottomFragment;

    public static VideoOneTypeFragment newInstance(String videoType, Integer videoCount, BaseBottomFragment baseBottomFragment) {
        final Bundle args = new Bundle();
        args.putString(ARG_VIDEO_TYPE, videoType);
        args.putInt(ARG_VIDEO_COUNT, videoCount);
        final VideoOneTypeFragment fragment = new VideoOneTypeFragment();
        fragment.baseBottomFragment = baseBottomFragment;
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle args = getArguments();
        if (args != null) {
            mVideoCount = args.getInt(ARG_VIDEO_COUNT);
            mVideoType = args.getString(ARG_VIDEO_TYPE);
        }
    }

    @Override
    public Object setLayout() {
        return R.layout.fragment_videos_one_type;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View root) {
        videoListTitle = $(R.id.videoListTitle);
        videoListTitle.setText(mVideoType);
        videoListMore = $(R.id.videoListMore);
        icon_back = $(R.id.icon_back);
        if(mVideoCount > ItemType.VIDEO_DEFAULT_COUNT) {
            icon_back.setVisibility(View.VISIBLE);
            videoListMore.setVisibility(View.INVISIBLE);
            videoListTitle.setVisibility(View.INVISIBLE);
        }
        icon_back.setOnClickListener(this);
        videoListMore.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == icon_back.getId()){
            pop();
        } else {
            // videoListMore
            VideoOneTypeFragment videoOneTypeFragment = VideoOneTypeFragment.newInstance(mVideoType, 9999, baseBottomFragment);
            baseBottomFragment.getSupportDelegate().start(videoOneTypeFragment);
        }
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
//        getSupportDelegate().loadRootFragment(R.id.movie_title_container, VideoTitleFragment.newInstance(mVideoType));
        getSupportDelegate().loadRootFragment(R.id.movie_container, VideoBlockFragment.newInstance(mVideoType, mVideoCount, baseBottomFragment));
    }
}
